package com.saver.modules.sys.dao;

import com.saver.modules.sys.entity.SysMenuEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface SysMenuDao extends JpaRepository<SysMenuEntity, Integer> {

    @Query(value = "select (select title FROM sys_menu s where s.id=sm.parent_id) as parentName,ord,id,view,parent_id parentId,name,title,icon,is_system isSystem,hide_in_bread hideInBread,hide_in_menu hideInMenu,show_always showAlways,path from sys_menu sm where sm.id=?1",nativeQuery = true)
    Map<String,Object> findId(Integer id);

    @Query(value = "select ord,id,view,parent_id parentId,name,title,icon,is_system isSystem,hide_in_bread hideInBread,hide_in_menu hideInMenu,show_always showAlways,path,(select count(*) FROM sys_menu where parent_id=sm.id) childrenCount from sys_menu sm order by parent_id,ord,id desc",nativeQuery = true)
    List< Map<String,Object>> findAllMenu();
}
